/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/10 14:05
 * @Copyright
 * */
package IO2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamTest4 {
    public static void main(String[] args) {
        FileInputStream fis=null;
        try {
            //文件路径：相对路径
            fis=new FileInputStream("temp");
            //循环读取
            byte[] bytes=new byte[1024]; //每次读取1KB
while (true){
                int temp=fis.read(bytes);
                if (temp==-1)break;
                //将byte数组中有效的字节数组转换成字符串
                System.out.println(new String(bytes,0,temp));
            }

            //循环升级
            int temp=0;
            while ((temp = fis.read(bytes)) !=-1){
                System.out.println(new String(bytes,0,temp));
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }catch (IOException e){
            throw new RuntimeException(e);
        }finally {
            if (fis!=null){
                try {
                    fis.close();
                }catch (IOException e){
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
